package com.ruoyi.qd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.qd.vo.RobotPageRes;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qd.domain.Robot;
import com.ruoyi.qd.service.IRobotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.mybatisflex.core.paginate.Page;
import com.ruoyi.common.core.page.PageDomain;

/**
 * 机器人Controller
 * 
 * @author tushiguang
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/qd/robot")
public class RobotController extends BaseController {
    @Autowired
    private IRobotService robotService;

    /**
     * 查询机器人列表
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageDomain pageDomain, Robot robot) {
        Page<RobotPageRes> page = robotService.selectRobotPage(pageDomain, robot);
        return getFlexTable(page);
    }

    /**
     * 主页机器人列表
     * @return
     */
    @Anonymous
    @GetMapping("/listAll")
    public AjaxResult list() {
        return success(robotService.selectRobotList());
    }

    /**
     * 查询可用的机器人集合
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:listUsable')")
    @GetMapping("/listUsable")
    public AjaxResult listUsable() {
        return success(robotService.listUsable());
    }

    /**
     * 导出机器人列表
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:export')")
    @Log(title = "机器人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Robot robot) {
        List<Robot> list = robotService.selectRobotList(robot);
        ExcelUtil<Robot> util = new ExcelUtil<Robot>(Robot.class);
        util.exportExcel(response, list, "机器人数据");
    }

    /**
     * 获取机器人详细信息
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(robotService.selectRobotById(id));
    }

    /**
     * 新增机器人
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:add')")
    @Log(title = "机器人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Robot robot) {
        return toAjax(robotService.insertRobot(robot));
    }

    /**
     * 修改机器人
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:edit')")
    @Log(title = "机器人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Robot robot) {
        return toAjax(robotService.updateRobot(robot));
    }

    /**
     * 删除机器人
     */
    @PreAuthorize("@ss.hasPermi('qd:robot:remove')")
    @Log(title = "机器人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(robotService.deleteRobotByIds(ids));
    }
}
